<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台（PHP版）
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码，建议反馈是我们前进的动力
// | 开源版本可自由商用，可去除界面版权logo
// | gitee下载：https://gitee.com/likeshop_gitee/likeadmin
// | github下载：https://github.com/likeshop-github/likeadmin
// | 访问官网：https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------


namespace app\adminapi\lists;


use app\common\lists\BaseDataLists;

/**
 * 管理员模块数据列表基类
 * Class BaseAdminDataLists
 * @package app\adminapi\lists
 */
abstract class BaseAdminDataLists extends BaseDataLists {

    protected array $adminInfo;
    protected int $adminId;
    protected int $adminCid;

    public function __construct() {
        parent::__construct();
        $this->adminInfo = $this->request->adminInfo;
        $this->adminId = $this->request->adminId;
        $this->adminCid = $this->request->adminInfo['cid'] ?? 0;
    }

    /**
     * 房间设备信息求和
     * @param $arr
     * @param $key
     * @param $count
     * @return float
     */
    public function array_sum_total($arr, $key, $count, $addend = 0) {
        $total_arr = array_column($arr, $key);
        if ($count > 0) {
            $total = array_sum($total_arr) / $count;
        } else {
            $total = array_sum($total_arr) * 0;
        }
        $total = $total + $addend * 1;
        return sprintf("%.6f", $total);
    }

    public function add_up($many, $one, $two) {
        return 1 * sprintf("%.{$many}f", $one * 1 + $two * 1);
    }

    public function array_average($array, $many = 2) {
        $num = array_sum($array) / (count($array) == 0 ? 1 : count($array));
        return 1 * sprintf("%.{$many}f", $num * 1);
    }

}

